import datetime

from django.contrib.auth.models import User
from django.db import models
import django.utils.timezone
from djangoProject1 import settings


class ImageStorage(models.Model):
    #外键关联一个用户，自增id默认有
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
    photo = models.ImageField(upload_to='images')
    hasEstablished = models.BooleanField(default=False)


# "大"任务，一个用户有多个大任务，需要标注的图片与具体的"大"任务关联
class MissionStorage(models.Model):
    # 发布任务的用户
    establisher = models.ForeignKey(User, on_delete=models.CASCADE, blank=False, related_name="owner")
    des = models.TextField(blank=True)
    # 领取任务的用户，可以是空
    taker = models.ForeignKey(User, on_delete=models.CASCADE, blank=True,null=True, related_name="takerOf")
    date = models.DateField(default=django.utils.timezone.now())
    urgency = models.DateField(default=(django.utils.timezone.now() + django.utils.timezone.timedelta(days=7)))
    finished = models.BooleanField(default=False)

# 具体子任务，与MissionStorage和图片实体关联
class TaskStorage(models.Model):
    belonging = models.ForeignKey(MissionStorage, on_delete=models.CASCADE)
    photo = models.ForeignKey(ImageStorage, on_delete=models.CASCADE)
    finished = models.BooleanField(default=False)
    finishedfile = models.FileField(upload_to='markingfiles', blank=True)

